#include "includes.h"

const u8 LinkCmd14230[6] = 
{
    0xc2, 0x33, 0xf1, 0x01, 0x00, 0xe7
};

const u8 EnterCmd14230[5] =
{
    0xc1, 0x33, 0xf1, 0x81, 0x66
};

u8 DSCmd14230[6] =
{
    0xc2, 0x33, 0xf1, 0x01, 0x00, 0x00
};

const u8 DTCCmd14230[5] =
{
    0xc1, 0x33, 0xf1, 0x03, 0xe8
};

const u8 CDTCCmd14230[5] =
{
    0xc1, 0x33, 0xf1, 0x04, 0xe9
};

int iso14230_4addr_link(void)
{
    int ret = -1;
    u8 i;
    ErrorStatus err;

    printk("Link...\r\n");
    if(wakeup_addr(0x33) == SUCCESS) {
        for(i = 0; i < 2; i++) {
            send_kwp2000_frame((u8 *)LinkCmd14230, &err);
            OSTimeDly(OS_TICKS_PER_SEC * 1);
            if(err == SUCCESS) {
                printk("OK\r\n");
                ret = 0;
                break;
            } else if(err == ERROR && i >= 1) {
                ret = -1;
            }
        }
    }

    return ret;
}


s16 iso14230_4addr_readEnginSpeed(void)
{
    ErrorStatus err;
    s16 val = -1;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x0c;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 4;
    } else {
        val = -1;
    }

    return val;
}

u8 iso14230_4addr_get_error_code(u16 *codes)
{
    u8 *ram, i;
    u16 dtc;
    ErrorStatus err;
    u8 num = 0;

    ram = send_kwp2000_frame((u8 *)&DTCCmd14230, &err);
    if(err == SUCCESS) {
        for(i = 0; i < 10; i++) {
            dtc = (u16)(*(ram + 4 + 2 * i) << 8 |
                    *(ram + 5 + 2 * i));
            if(dtc != 0) {
                codes[num ++] = dtc;
            }
        }
    } else {
        printk("%s: failed to do dtc\r\n", __func__);
        num = 0xff;
    }

    return num;
}

int iso14230_4addr_clear_error_code(void)
{
    int ret;
    ErrorStatus err;

    send_kwp2000_frame((u8 *)&CDTCCmd14230, &err);
    if(err == SUCCESS) {
        ret = 0;
    } else {
        printk("%s: failed to do cdtc\r\n", __func__);
        ret = -1;
    }

    return ret;
}

u8 iso14230_4addr_get_payload(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x04;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = 0xff;
    }

    return val;
}

u8 iso14230_4addr_get_ect(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x05;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] - 40;
    } else {
        val = 0xff;
    }

    return val;
}

u16 iso14230_4addr_get_speed(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x0d;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4addr_get_mil_distance(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x21;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = (ram[5] << 8) | (ram[6]);
    } else {
        val = 0xffff;
    }

    return val;
}

float iso14230_4addr_get_relative_frp(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x22;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 5177.27 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_frp(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x23;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 10;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x24;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x24;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x26;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x27;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x27;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x28;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x28;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x29;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x29;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2A;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2A;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2b;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2vol_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2b;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_egr(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2c;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_egr_error(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2d;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[6] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ioep(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2e;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_fuel_level_input(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x2f;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

u16 iso14230_4addr_get_after_start_times(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x30;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4addr_get_after_distance(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x31;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = (ram[5] << 8) | ram[6];
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4addr_get_emission_sys_press(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x32;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 4;
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4addr_get_press(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x33;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

float iso14230_4addr_get_o2cur_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x34;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x34;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x35;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x35;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x36;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x36;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x37;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x37;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x38;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x38;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x39;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x39;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3a;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3a;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_o2cur_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3b;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_ratio2_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3b;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_cat_temp_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3c;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_cat_temp_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3d;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_cat_temp_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3e;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_cat_temp_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x3f;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_short_fuel_adj_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x06;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_long_fuel_adj_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x07;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4addr_get_short_fuel_adj_2(void)
{
    float val = -1;    
    printk("Unsupported!\r\n");

    return val;
}

float iso14230_4addr_get_long_fuel_adj_2(void)
{
    float val = -1;    
    printk("Unsupported!\r\n");

    return val;
}

u8 iso14230_4addr_get_gas_temp(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x0f;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] - 40;
    } else {
        val = 0xff;
    }

    return val;
}

float iso14230_4addr_get_throttle_pos(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230[4] = 0x11;
    ram = send_kwp2000_frame(DSCmd14230, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

